import xlrd



class BuyData:

    # 零钱
    def buy_small_change_data(self):
        return self.read_data(sheet_name='Sheet1')

    # 基金
    def buy_fund_data(self):
        return self.read_data(sheet_name='Sheet2')

    # 股票
    def buy_share_certificate_data(self):
        return self.read_data(sheet_name='Sheet3')

    # 无支付密码
    def not_buyPwd_data(self):
        wordBook = xlrd.open_workbook(filename='../TestData/test_buy_data.xls')
        sheet = wordBook.sheet_by_name('Sheet4')
        arr = []
        for i in range(1, sheet.nrows):
            e = sheet.row_values(i)

            if type(e[1]) is float:
                e[1] = str(int(e[1]))

            if type(e[2]) is float:
                e[2] = str(int(e[2]))

            e[3] = e[3].split(',')
            arr.append(e)
        return arr

    def many_bankCard_data(self):
        wordBook = xlrd.open_workbook(filename='../TestData/test_buy_data.xls')
        sheet = wordBook.sheet_by_name('Sheet5')
        arr = []
        for i in range(1, sheet.nrows):
            e = sheet.row_values(i)
            if type(e[1]) is float:
                e[1] = str(int(e[1]))

            if type(e[2]) is float:
                e[2] = str(int(e[2]))

            arr2 = e[3].split('\n')
            for j in range(len(arr2)):
                arr2[j] = arr2[j].split(',')
            e[3] = arr2
            e[4] = e[4].split(',')
            arr.append(e)

        return arr


    def not_bankCard_data(self):
        wordBook = xlrd.open_workbook(filename='../TestData/test_buy_data.xls')
        sheet = wordBook.sheet_by_name('Sheet6')
        arr = []
        for i in range(1, sheet.nrows):
            e = sheet.row_values(i)
            if type(e[1]) is float:
                e[1] = str(int(e[1]))

            if type(e[2]) is float:
                e[2] = str(int(e[2]))

            arr.append(e)
        return arr

    def read_data(self,sheet_name):
        wordBook = xlrd.open_workbook(filename='../TestData/test_buy_data.xls')
        sheet = wordBook.sheet_by_name(sheet_name)
        arr = []
        for i in range(1, sheet.nrows):
            e = sheet.row_values(i)
            if type(e[1]) is float:
                e[1] = str(int(e[1]))

            if type(e[2]) is float:
                e[2] = str(int(e[2]))
            if len(e[3]) != 0:
                e[3] = e[3].split(',')
            else:
                e[3] = []
            e[4] = e[4].split(',')
            arr.append(e)
        return arr


